<?php

namespace app\api\logic;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dingtalk\Vdrive_1_0\Dingtalk;
//use AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Dingtalk as Dingtalk1;

use AlibabaCloud\SDK\Dingtalk\Vdrive_1_0\Models\ListSpacesHeaders;
use AlibabaCloud\SDK\Dingtalk\Vdrive_1_0\Models\ListSpacesRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class CloudDiskLogic extends BaseSDKLogic
{
    private function createClient(){
        $config = new Config([]);
        $config->protocol = "https";
        $config->regionId = "central";
        return new Dingtalk($config);
    }

    // 获取用户空间列表
    public function spaceList()
    {
        $client = $this->createClient();

        $listSpacesHeaders = new ListSpacesHeaders([]);
        $listSpacesHeaders->xAcsDingtalkAccessToken = $this->accessToken();
        $listSpacesRequest = new ListSpacesRequest([
            "unionId" => "yIuD7JiSmiPiSQuPjEv9Zii7SwiEiE",
            "spaceType" => "org",
//            "nextToken" => "2CMlB97VtVJWfoVliPIXPUQiEiE",
            "maxResults" => 50
        ]);

        return $client->listSpacesWithOptions($listSpacesRequest, $listSpacesHeaders, $this->runtimeOptions);

//        return

    }

    // 空间下所有文件或文件夹列表
    public function folder()
    {
        $config = new Config([]);
        $config->protocol = "https";
        $config->regionId = "central";
        $client = new \AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Dingtalk($config);

        $listAllDentriesHeaders = new \AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesHeaders([]);

        $listAllDentriesHeaders->xAcsDingtalkAccessToken = $this->accessToken();
        $option = new \AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesRequest\option([
            "nextToken" => "3678056xxxxx",
            "maxResults" => 30,
            "order" => "DESC",
            "withThumbnail" => true
        ]);
        $listAllDentriesRequest = new \AlibabaCloud\SDK\Dingtalk\Vstorage_1_0\Models\ListAllDentriesRequest([
            "unionId" => "yIuD7JiSmiPiSQuPjEv9Zii7SwiEiE",
//            "option" => $option
        ]);

        $rr = $client->listAllDentriesWithOptions("275266943", $listAllDentriesRequest, $listAllDentriesHeaders, $this->runtimeOptions);

        return $rr;
    }
}